<!DOCTYPE html>
<html>
<uieip type="page" value="login" debug="true" timeout="5000"></uieip>
<uieip type="reg" value="console"></uieip>

<head>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min"></uieip>
    <uieip type="file" value="js" src="/yqwin/src/yqwin.min"></uieip>
    <title>Data Edit</title>

    <style>
        table.main_tb {
            border-spacing: 0px;
        }

        table.main_tb>tbody>tr>td,
        table.main_tb>tr>td {
            padding: 0px;
        }
    </style>
</head>

<body>
    <table class="main_tb">
        <tr>
            <td>
                <div style="margin: 4px 0 4px 4px">
                    <select id="cg_fs" style="width: 300px;"></select>
                </div>
            </td>
            <td rowspan="2" style="vertical-align: top;padding: 3px 0 0 4px;">
                <div id="tt" data-options="border:false" class="easyui-tabs" style="width:700px;height:250px">
                    <div title="关联文件" style="padding:0px">
                        <table id="cg_rellink" style="width:100%;height: 250px;"></table>
                    </div>
                    <div title="未关联文件" style="padding:0px">
                        <table id="cg_nulllink" style="width:100%;height: 250px;"></table>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <table id="cg_file_rel" style="width:100%;height: 250px; "></table>
            </td>
        </tr>
    </table>
    <script>
        function form_load() {
            $(window).resize(function () {
                onresize();
            });
            onresize();

            $.yqFileList({
                ajaxUrl: "_file.html"
            }, function (data) {
                //console.log(JSON.stringify(data));
                if (data.error == 0) {
                    $("#cg_fs").yqComboGrid("setData", data);
                }
            });
        }

        function onresize() {
            var w = window.innerWidth - 4;
            var h = window.innerHeight;

            var lwidth = 330;
            $('#cg_fs').yqComboGrid("resize", {
                width: lwidth - 6
            });

            $("#cg_file_rel").yqDataGrid("resize", {
                width: lwidth,
                height: h - 38
            });

            var tabs_w = w - lwidth;
            var tabs_h = h-3;
            $("#tt").tabs("resize", {
                width: tabs_w,
                height: tabs_h
            });

            tabs_w = tabs_w;
            tabs_h = tabs_h - 34;
            $("#cg_rellink").yqDataGrid("resize", {
                width: tabs_w,
                height: tabs_h
            });

            $("#cg_nulllink").yqDataGrid("resize", {
                width: tabs_w,
                height: tabs_h
            });
        }

        $(function () {
            init_fs()
        });

        function init_fs() {
            $("#cg_fs").yqComboGrid({
                titles: fs_titles,
                keyId: "name",                      //关键字段
                displayMember: "describe",          //显示字段
                loadData: false,
                isEdit: false, //可编辑
                isSeek: false,

                isPage: false,                   //分页

                afterBindingTitle: function () {
                    init_file_rel();
                }, //标题绑定后
                onChange: function (newValue, newRow, oldValue, oldRow) {
                    $("#cg_file_rel").yqDataGrid("clear");
                    $("#cg_rellink").yqDataGrid("clear");
                    $("#cg_nulllink").yqDataGrid("clear");

                    if (!(newValue === null)) {
                        var row = $("#cg_fs").yqComboGrid("getSelected");
                        $.yqFileRelTypes({
                            ajaxUrl: '/_file.html',
                            sto_type: row["type"],
                            sto_name: row["name"],
                        }, function (data) {
                            //console.log(JSON.stringify(data));
                            if (data.error == 0) {
                                $("#cg_file_rel").yqDataGrid("setData", data);
                                $("#cg_nulllink").yqDataGrid("seek", "");
                            }
                        });
                    }
                },
            });
        }

        var fs_titles = [{
            "name": "name",
            "ui_title": "名称",
            "ui_type": 2,
            "ui_width": 70,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
            }
        }, {
            "name": "type",
            "ui_title": "类型",
            "ui_type": 6,
            "ui_width": 40,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "blank": false,
                "lists": [
                    {
                        "no": 1,
                        "name": "db"
                    },
                    {
                        "no": 2,
                        "name": "fs"
                    }
                ]
            }
        }, {
            "name": "describe",
            "ui_title": "描述",
            "ui_type": 2,
            "ui_width": 120,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
            }
        }, {
            "name": "db_type",
            "ui_title": "数据库类型",
            "ui_type": 2,
            "ui_width": 100,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {

            }
        }, {
            "name": "fs_type",
            "ui_title": "文件存储类型",
            "ui_type": 2,
            "ui_width": 110,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
            }
        }];

        function init_file_rel() {
            $("#cg_file_rel").yqDataGrid({
                keyId: "tb_name",
                titles: file_rel_titles,
                loadData: false,
                isEdit: false,
                isPage: false,
                isSimple: false,
                isSeek: false,
                afterBindingTitle: function () {
                    init_rellink();
                },
                onClickRow: function (index, row) {     //点击行
                    if (row == null) {
                        $("#cg_rellink").yqDataGrid("clear");
                    }
                    else {
                        $("#cg_rellink").yqDataGrid("setBindingValue", row["tb_name"]);
                        $("#cg_rellink").yqDataGrid("seek", "");
                    }
                },
            });
        }

        var file_rel_titles = [{
            "name": "db_name",
            "ui_title": "db_name",
            "ui_type": 2,
            "ui_width": 100,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "tb_name",
            "ui_title": "tb_name",
            "ui_type": 2,
            "ui_width": 160,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }
        ];

        function init_rellink() {
            $("#cg_rellink").yqDataGrid({
                keyId: "sid",
                bindingKeyId: "tb_name",
                bindingValue: null,
                order: "",
                titles: rellink_titles,

                loadData: false,
                isEdit: false,
                isPage: true,
                pageSize: 25,
                isSimple: true,
                isSeek: false,
                afterBindingTitle: function () {
                    init_nulllink();
                },
                beforeLoadData: function (opts, callback) {   //opts：查询参数，data：未null时，默认查询；不是null，外部查询
                    var fs_row = $("#cg_fs").yqComboGrid("getSelected");
                    opts.ajaxUrl = '/_file.html';
                    opts.sto_type = fs_row["type"];
                    opts.sto_name = fs_row["name"];
                    $.yqFileRelPaging(opts, function (data) {
                        //console.log(JSON.stringify(data));
                        callback(opts, data);
                    });
                },
            });
        }

        var rellink_titles = [{
            "name": "tb_id",
            "ui_title": "tb_id",
            "ui_type": 2,
            "ui_width": 300,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "tb_field",
            "ui_title": "tb_field",
            "ui_type": 2,
            "ui_width": 70,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "name",
            "ui_title": "名称",
            "ui_type": 2,
            "ui_width": 230,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "type",
            "ui_title": "类型",
            "ui_type": 2,
            "ui_width": 90,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "size",
            "ui_title": "大小",
            "ui_type": 10,
            "ui_width": 80,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "linknum",
            "ui_title": "关联数",
            "ui_type": 10,
            "ui_width": 80,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "c_username",
            "ui_title": "创建人",
            "ui_type": 2,
            "ui_width": 120,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }, {
            "name": "createtime",
            "ui_title": "创建时间",
            "ui_type": 12,
            "ui_width": 140,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {}
        }
        ];

        function init_nulllink() {
            $("#cg_nulllink").yqDataGrid({
                keyId: "sid",
                order: "",
                titles: nulllink_titles,
                loadData: false,
                loadData: false,
                isEdit: false,
                isPage: true,
                pageSize: 25,
                isSimple: true,
                isSeek: false,
                afterBindingTitle: function () {
                    form_load();
                },
                beforeLoadData: function (opts, callback) {
                    var fs_row = $("#cg_fs").yqComboGrid("getSelected");
                    if (fs_row === null) {
                        callback(opts, { rows: [] });
                    } else {
                        opts.ajaxUrl = '/_file.html';
                        opts.sto_type = fs_row["type"];
                        opts.sto_name = fs_row["name"];
                        $.yqFileNullPaging(opts, function (data) {
                            //console.log(JSON.stringify(data));
                            callback(opts, data);
                        });
                    }
                },
            });
        }

        var nulllink_titles = [
            {
                "name": "name",
                "ui_title": "名称",
                "ui_type": 2,
                "ui_width": 230,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }, {
                "name": "type",
                "ui_title": "类型",
                "ui_type": 2,
                "ui_width": 90,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }, {
                "name": "size",
                "ui_title": "大小",
                "ui_type": 10,
                "ui_width": 80,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }, {
                "name": "complete",
                "ui_title": "上传完成",
                "ui_type": 3,
                "ui_width": 50,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }, {
                "name": "c_username",
                "ui_title": "创建人",
                "ui_type": 2,
                "ui_width": 120,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }, {
                "name": "createtime",
                "ui_title": "创建时间",
                "ui_type": 12,
                "ui_width": 140,
                "ui_visible": true,
                "ui_readonly": false,
                "ui_mask": {}
            }
        ];
    </script>
</body>

</html>